﻿//===============================================================================
// Microsoft patterns & practices
// Composite Application Guidance for Windows Presentation Foundation
//===============================================================================
// Copyright (c) Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================
using System.Windows;
using Microsoft.Practices.Composite.Events;
using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Composite.UnityExtensions;
using Microsoft.Practices.Unity;
using WpfTwitterClient.Infrastructure.Services;
using WpfTwitterClient.Modules.Status;
using WpfTwitterClient.Modules.Timelines;

namespace WpfTwitterClient
{
    using Modules.Authorization;

    internal class Bootstrapper : UnityBootstrapper
    {
        protected override DependencyObject CreateShell()
        {
            MainWindow mainWindow = this.Container.Resolve<MainWindow>();

            if (mainWindow != null)
            {
                mainWindow.Show();
            }

            return mainWindow;
        }

        protected override void InitializeModules()
        {
            Container.RegisterType<IEventAggregator, EventAggregator>(new ContainerControlledLifetimeManager());
            Container.RegisterType<ICacheService, CacheService>(new ContainerControlledLifetimeManager());
            Container.RegisterType<ITwitterClient, TwitterClient>(new ContainerControlledLifetimeManager());

            ITwitterClient client = Container.Resolve<ITwitterClient>();

            IModule statusModule = this.Container.Resolve<StatusModule>();
            IModule timelineModule = this.Container.Resolve<TimelinesModule>();
            IModule authorizationModule = this.Container.Resolve<AuthorizationModule>();

            statusModule.Initialize();
            timelineModule.Initialize();
            authorizationModule.Initialize();

            client.Initialize();
        }
    }
}